home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / HeadC.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  11.5 KB  |  403 lines

  1. class classes.enemy.HeadC
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var id;
  7.    var clip;
  8.    var fire;
  9.    var colorR;
  10.    var trans;
  11.    var colorTrans;
  12.    var f2;
  13.    var dir;
  14.    var axis;
  15.    var xDest;
  16.    var yDest;
  17.    var ep;
  18.    var oldDir;
  19.    var xMov = 0;
  20.    var yMov = 0;
  21.    var xMovT = 0;
  22.    var yMovT = 0;
  23.    var speedOrig = 9;
  24.    var speed = 9;
  25.    var xDestMet = false;
  26.    var yDestMet = false;
  27.    var c = 0;
  28.    var life = 10;
  29.    var nc = 0;
  30.    var xA = 0;
  31.    var yA = 0;
  32.    var nudging = false;
  33.    var hc = 0;
  34.    var power = 15;
  35.    var flashing = false;
  36.    var flashC = 0;
  37.    var Name = "headC";
  38.    function HeadC(px, py, pmoveScript, pid)
  39.    {
  40.       this.x = px;
  41.       this.y = py;
  42.       this.moveScript = pmoveScript.slice();
  43.       this.id = pid;
  44.       _root.d = _root.d + 1;
  45.       this.clip = _root.attachMovie("headC","headC" + this.id + "Clip",_root.d + 50000);
  46.       this.clip._x = this.x;
  47.       this.clip._y = this.y;
  48.       this.speedVar();
  49.       this.fire = new Object();
  50.       this.speed *= _root.dif.speed;
  51.       this.speedOrig = this.speed;
  52.       this.life *= _root.dif.life;
  53.       this.colorR = _root.randRange(-10,30);
  54.       this.trans = new flash.geom.Transform(this.clip);
  55.       this.colorTrans = new flash.geom.ColorTransform(1,1,1,1,this.colorR,this.colorR,this.colorR,0);
  56.       this.trans.colorTransform = this.colorTrans;
  57.       this.parseMoveScript();
  58.       if(_root.flashing)
  59.       {
  60.          this.flashing = true;
  61.          _root.flashing = false;
  62.       }
  63.       _root.stats.created = _root.stats.created + 1;
  64.    }
  65.    function nudge(pxA, pyA, pscale)
  66.    {
  67.       this.nc = 0;
  68.       this.nudging = true;
  69.       var _loc2_ = pscale / 100;
  70.       this.xA = pxA * _loc2_;
  71.       this.yA = pyA * _loc2_;
  72.    }
  73.    function speedVar()
  74.    {
  75.       if(random(3) == 1)
  76.       {
  77.          this.speed *= _root.randRange2(0.9998,1.0002);
  78.       }
  79.    }
  80.    function bombed(num)
  81.    {
  82.       this.f2 = "death";
  83.    }
  84.    function parseMoveScript()
  85.    {
  86.       this.dir = this.moveScript[0];
  87.       if(this.dir == "break")
  88.       {
  89.          delete this.moveScript;
  90.          this.fireBall();
  91.       }
  92.       else
  93.       {
  94.          this[this.axis + "MovT"] = 0;
  95.          this.f2 = "gotoXYDest";
  96.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  97.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  98.          this.speedVar();
  99.          if(this.dir == "L" || this.dir == "U")
  100.          {
  101.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  102.          }
  103.          else
  104.          {
  105.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  106.          }
  107.          this.moveScript.splice(0,2);
  108.       }
  109.    }
  110.    function gotoXYDest()
  111.    {
  112.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  113.       {
  114.          if(this.axis == "x")
  115.          {
  116.             this.x = this.xDest;
  117.          }
  118.          else
  119.          {
  120.             this.y = this.yDest;
  121.          }
  122.          this.parseMoveScript();
  123.       }
  124.    }
  125.    function getDirString()
  126.    {
  127.       if(this.xMovT < -1)
  128.       {
  129.          this.dir = "L";
  130.       }
  131.       else if(this.xMovT > 1)
  132.       {
  133.          this.dir = "R";
  134.       }
  135.       else if(this.yMovT > 1)
  136.       {
  137.          this.dir = "D";
  138.       }
  139.       else if(this.yMovT < -1)
  140.       {
  141.          this.dir = "U";
  142.       }
  143.    }
  144.    function wander()
  145.    {
  146.       if(random(100) > 70 || (this.x > 950 || this.x < 50 || this.y < 50 || this.y > 550))
  147.       {
  148.          if(random(20) > 18)
  149.          {
  150.             this[this.axis + "MovT"] = 0;
  151.             this.f2 = "wait";
  152.             this.c = 0;
  153.             this.ep = _root.randRange(30,120);
  154.             this.ep *= 1 / _root.dif.speed;
  155.          }
  156.          else if(random(10) > 1)
  157.          {
  158.             this.dir = _root.getDir(this.x,this.y);
  159.             this[this.axis + "MovT"] = 0;
  160.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  161.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  162.             this.speedVar();
  163.          }
  164.          else
  165.          {
  166.             this[this.axis + "MovT"] = 0;
  167.             this.axis = random(10) <= 4 ? "y" : "x";
  168.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  169.             this.getDirString();
  170.          }
  171.       }
  172.       if(random(200) > 197 + _root.dif.wait)
  173.       {
  174.          this.fireBall();
  175.       }
  176.    }
  177.    function wait()
  178.    {
  179.       this.c = this.c + 1;
  180.       if(this.c >= this.ep)
  181.       {
  182.          this.f2 = "wander";
  183.          if(random(10) > 2)
  184.          {
  185.             this.dir = _root.getDir(this.x,this.y);
  186.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  187.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  188.             this.speedVar();
  189.          }
  190.          else
  191.          {
  192.             this.axis = random(10) <= 4 ? "y" : "x";
  193.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  194.             this.getDirString();
  195.          }
  196.       }
  197.       if(random(100) > 95)
  198.       {
  199.          var _loc3_ = ["L","R","F"];
  200.          this.dir = _loc3_[random(_loc3_.length)];
  201.       }
  202.    }
  203.    function fireBall()
  204.    {
  205.       this.dir = "F";
  206.       this.xMovT = 0;
  207.       this.yMovT = 0;
  208.       this.clip.body.eyes.gotoAndStop("F");
  209.       this.clip.body.eyes.clip.gotoAndPlay("glow");
  210.       this.fire.c = 0;
  211.       this.f2 = "firing";
  212.       _root.audio.playLevel3("headCFire" + (random(2) + 1),_root.randRange(15,25));
  213.    }
  214.    function firing()
  215.    {
  216.       this.fire.c = this.fire.c + 1;
  217.       if(this.fire.c == 11)
  218.       {
  219.          _root.enemyShotID = _root.enemyShotID + 1;
  220.          _root["fireBall" + _root.enemyShotID] = new classes.shots.FireBall(this.x,this.y,_root.enemyShotID);
  221.          _root.addEnemyShot("fireBall" + _root.enemyShotID);
  222.       }
  223.       if(this.fire.c == 25)
  224.       {
  225.          this.f2 = "wander";
  226.          if(random(10) > 2)
  227.          {
  228.             this.dir = _root.getDir(this.x,this.y);
  229.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  230.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  231.             this.speedVar();
  232.          }
  233.          else
  234.          {
  235.             this.axis = random(10) <= 4 ? "y" : "x";
  236.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  237.             this.getDirString();
  238.          }
  239.       }
  240.    }
  241.    function death()
  242.    {
  243.       _root.stats.destroyed = _root.stats.destroyed + 1;
  244.       _root.stats.score += 2500;
  245.       _root.powerUp(this.x,this.y,93);
  246.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(60,80),_root.randRange(75,100),"Red"]);
  247.       var _loc3_ = 0;
  248.       var _loc4_ = random(3);
  249.       while(_loc3_ < _loc4_)
  250.       {
  251.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"headC","Red"]);
  252.          _loc3_ = _loc3_ + 1;
  253.       }
  254.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"red"]);
  255.       _root.audio.playLevel4("headX" + (random(3) + 1),_root.randRange(15,25));
  256.       _root.removeChar("headC" + this.id);
  257.       this.f2 = "";
  258.    }
  259.    function death2()
  260.    {
  261.       _root.removeChar("headC" + this.id);
  262.       this.f2 = "";
  263.    }
  264.    function main()
  265.    {
  266.       if(this.flashing)
  267.       {
  268.          this.flashC = this.flashC + 1;
  269.          var _loc8_ = 275 - this.flashC * 10;
  270.          this.colorTrans.greenOffset = _loc8_;
  271.          this.colorTrans.redOffset = _loc8_;
  272.          this.colorTrans.blueOffset = _loc8_;
  273.          this.trans.colorTransform = this.colorTrans;
  274.          if(this.flashC == 27)
  275.          {
  276.             this.colorTrans.greenOffset = 0;
  277.             this.colorTrans.redOffset = 0;
  278.             this.colorTrans.blueOffset = 0;
  279.             this.trans.colorTransform = this.colorTrans;
  280.             delete this.flashing;
  281.             delete this.flashC;
  282.          }
  283.       }
  284.       this[this.f2]();
  285.       if(this.oldDir != this.dir)
  286.       {
  287.          if(this.oldDir == undefined || this.dir == "F")
  288.          {
  289.             this.clip.body.eyes.gotoAndStop(this.dir);
  290.          }
  291.          else if(this.dir == "U" || this.dir == "D")
  292.          {
  293.             this.clip.body.eyes.gotoAndStop(this.oldDir);
  294.          }
  295.          else if(random(3) > 0)
  296.          {
  297.             if(this.dir == "R")
  298.             {
  299.                this.clip.body.eyes.gotoAndPlay("LtoR");
  300.             }
  301.             else
  302.             {
  303.                this.clip.body.eyes.gotoAndPlay("RtoL");
  304.             }
  305.          }
  306.          else
  307.          {
  308.             this.clip.body.eyes.gotoAndPlay("spin" + this.dir);
  309.          }
  310.       }
  311.       this.oldDir = this.dir;
  312.       if(this.nudging)
  313.       {
  314.          this.xA *= 0.5;
  315.          this.yA *= 0.5;
  316.          this.nc = this.nc + 1;
  317.          _loc8_ = 255 - this.nc * 17;
  318.          this.colorTrans.redOffset = _loc8_;
  319.          this.trans.colorTransform = this.colorTrans;
  320.          if(this.nc == 15)
  321.          {
  322.             this.xA = this.yA = 0;
  323.             this.nudging = false;
  324.             this.colorTrans.redOffset = this.colorR;
  325.             this.trans.colorTransform = this.colorTrans;
  326.          }
  327.       }
  328.       var _loc4_ = 0;
  329.       var _loc7_ = _root.broShots.length;
  330.       while(_loc4_ < _loc7_)
  331.       {
  332.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  333.          if(this.clip.hitTest(_root[_loc6_]))
  334.          {
  335.             var _loc3_ = _root.broShots[_loc4_];
  336.             var _loc5_ = this.life;
  337.             this.life -= _root[_loc3_].power;
  338.             if(this.life < 1)
  339.             {
  340.                this.f2 = "death";
  341.             }
  342.             else
  343.             {
  344.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  345.                _root.audio.playLevel4("headHit" + (random(4) + 1),_root.randRange(18,28));
  346.                this[this.axis + "MovT"] = 0;
  347.                this.axis = random(10) <= 4 ? "y" : "x";
  348.                this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  349.                this.getDirString();
  350.             }
  351.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  352.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  353.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  354.             _root[_loc3_].hit(_loc5_);
  355.             break;
  356.          }
  357.          _loc4_ = _loc4_ + 1;
  358.       }
  359.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  360.       {
  361.          _root[_root.char].stealCoins(15);
  362.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  363.          this.f2 = "death";
  364.       }
  365.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  366.       {
  367.          this.f2 = "death2";
  368.       }
  369.       if(this.xMovT < this.xMov)
  370.       {
  371.          this.xMov -= 0.3;
  372.       }
  373.       else if(this.xMovT > this.xMov)
  374.       {
  375.          this.xMov += 0.3;
  376.       }
  377.       else
  378.       {
  379.          this.xMov = this.xMovT;
  380.       }
  381.       if(this.yMovT < this.yMov)
  382.       {
  383.          this.yMov -= 0.3;
  384.       }
  385.       else if(this.yMovT > this.yMov)
  386.       {
  387.          this.yMov += 0.3;
  388.       }
  389.       else
  390.       {
  391.          this.yMov = this.yMovT;
  392.       }
  393.       if(random(100) > 98)
  394.       {
  395.          this.clip.body.eyes.clip.gotoAndPlay("blink");
  396.       }
  397.       this.x += this.xMov + this.xA;
  398.       this.y += this.yMov + this.yA + 0.5 * Math.sin(this.hc += 0.1);
  399.       this.clip._x = this.x;
  400.       this.clip._y = this.y;
  401.    }
  402. }
  403.